# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=taffybar
pkgver=4.0.1
pkgrel=33
pkgdesc="A desktop bar similar to xmobar, but with more GUI"
url="https://github.com/taffybar/taffybar"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-configfile' 'haskell-hstringtemplate' 'haskell-x11' 'haskell-aeson'
         'haskell-ansi-terminal' 'haskell-broadcast-chan' 'haskell-conduit' 'haskell-data-default'
         'haskell-dbus' 'haskell-dbus-hslogger' 'haskell-dyre' 'haskell-either'
         'haskell-enclosed-exceptions' 'haskell-gi-cairo' 'haskell-gi-cairo-connector'
         'haskell-gi-cairo-render' 'haskell-gi-gdk3' 'haskell-gi-gdkpixbuf' 'haskell-gi-gdk3x11'
         'haskell-gi-glib' 'haskell-gi-gtk3' 'haskell-gi-gtk-hs' 'haskell-gi-pango'
         'haskell-gtk-sni-tray' 'haskell-gtk-strut' 'haskell-gi' 'haskell-gi-base'
         'haskell-hslogger' 'haskell-http-client' 'haskell-http-client-tls' 'haskell-http-conduit'
         'haskell-http-types' 'haskell-multimap' 'haskell-old-locale' 'haskell-optparse-applicative'
         'haskell-rate-limit' 'haskell-regex-compat' 'haskell-safe' 'haskell-scotty' 'haskell-split'
         'haskell-status-notifier-item' 'haskell-time-locale-compat' 'haskell-time-units'
         'haskell-transformers-base' 'haskell-tuple' 'haskell-utf8-string' 'haskell-xdg-basedir'
         'haskell-xdg-desktop-entry' 'haskell-xml' 'haskell-xml-helpers' 'xmonad' 'gtk3')
makedepends=('ghc' 'uusi')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz"
        $pkgname-ghc-9.0-break.patch::https://github.com/taffybar/taffybar/commit/b57006885d35cee63244b1559813ca4b5990e04c.patch)
sha256sums=('88739d1a5a42f39df0c864e6578ff42681d6a2d8cc5658802c86c9af6a8c7b51'
            'e7557dd2ed13335b9231c387e35545227e6bd1fce6d264b7fccd9daa16c13501')

prepare() {
  cd $pkgname-$pkgver
  patch -Rp1 -i ../$pkgname-ghc-9.0-break.patch
  uusi -u scotty $pkgname.cabal
}

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' 

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
